Contents

import pandas as pd
import csv
import plotly.express as px
from plotly.offline import init_notebook_mode

init_notebook_mode()
import pandas as pd
import plotly.express as px

wb_df = pd.read_csv('../data/iunc_whales_only.csv')

custom_order = [
    "Critically Endangered",
    "Endangered",
    "Vulnerable",
    "Near Threatened",
    "Least Concern",
    "Data Deficient"
]

wb_df['redlistCategory'] = pd.Categorical(
    wb_df['redlistCategory'],
    categories=custom_order,
    ordered=True
)

color_map = {
    "Critically Endangered": "#3a5ba0",
    "Endangered": "#3a5ba0",
    "Vulnerable": "#3a5ba0",
    "Near Threatened": "#3a5ba0",
    "Least Concern": "#3a5ba0",
    "Data Deficient": "#999999"
}

fig = px.histogram(
    wb_df,
    x="redlistCategory",
    color="redlistCategory",
    category_orders={"redlistCategory": custom_order},
    labels={
        "redlistCategory": "Classification",
        "count": "Amount"
    },
    color_discrete_map=color_map
)

fig.update_layout(
    title={
        'text': 'Population trends for whale species',
        'x': 0.5,
        'xanchor': 'center'
    },
    height=600,
    xaxis={
        'title': 'Endangerment Classification (Red List Standards)',
        'categoryorder': 'array',
        'categoryarray': custom_order
    },
    yaxis={
        'title': 'Amount of Whale Species'
    },
    showlegend=False,
    margin=dict(b=100)
)

fig.show()